//
//  NavVC.swift
//  SelfGoodAsOldPhomes
//
//  Created by panda on 17/3/14.
//  Copyright © 2017年 panda. All rights reserved.
//

import UIKit

class NavVC: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var dataModels : [TableViewModel]?
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        initData();
        
        view.addSubview(tableView)
        
        
    }
    
    func initData() {
        dataModels = [TableViewModel.init(name: "1", imgStr: "1", iconStr: "my_logout"),
                      TableViewModel.init(name: "2", imgStr: "2", iconStr: "my_novice guide"),
                      TableViewModel.init(name: "3", imgStr: "3", iconStr: "my_order"),
                      TableViewModel.init(name: "4", imgStr: "4", iconStr: "my_update"),
                      TableViewModel.init(name: "新手引导", imgStr: "新手引导", iconStr: "my_order2")]
    }
    
    //MARK: - 懒加载
    lazy var tableView : UITableView = {
        let tableV = UITableView(frame: CGRect(x: 0, y: 0, width: 375, height: UIScreen.main.bounds.height));
        tableV.delegate = self
        tableV.dataSource = self
        tableV.separatorStyle =  UITableViewCellSeparatorStyle.singleLine;
        return tableV;
    }()
    
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    

}

extension NavVC {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1;
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (dataModels?.count)!;
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cellId = "cell";
        var cell = tableView.dequeueReusableCell(withIdentifier: cellId);
        if (cell == nil) {
            cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: cellId);
        }
        cell?.selectionStyle = UITableViewCellSelectionStyle.none;
        let dic = dataModels?[indexPath.row];
        cell?.imageView?.image = UIImage(named: (dic?.iconStr)!)
        cell?.textLabel?.text = dic?.title
        return cell!;
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 50;
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let nextVC = DetailVC();
        nextVC.model = dataModels?[indexPath.row];
        self.hidesBottomBarWhenPushed=true
        navigationController?.pushViewController(nextVC, animated: true)
        self.hidesBottomBarWhenPushed=false
    }
}
